#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#
#

from PIL import Image,ImageFont,ImageDraw
import os


#获取tmp的文件名到数组中
def get_file_list(path):
    list_name=[]
    files = os.listdir(path)
    files.sort()
    for file in files:
        file_path = os.path.join(path, file)
        list_name.append(file_path)
    return list_name


fontfilelist = get_file_list('./font')
print( fontfilelist)

black = Image.new("RGB",[28,28],"black")

drawobj = ImageDraw.Draw(black)



ft = ImageFont.truetype(fontfilelist[0], 28)
drawobj.text((0,-5), "W",font = ft, fill = 'white')


offsetx,offsety = ft.getoffset('W')
w,h = ft.getsize('W')

drawobj.rectangle((offsetx,offsety,offsetx+w,offsety+h),outline='red')


black.show()

black.save('./test.png')